<template>
	<view class="p-l-30 p-r-30 p-b-26" v-if="isObjNone(revenue)">

    <view class="uni-margin-wrap p-b-20">
      <swiper class="swiper" circular>
<!--        <swiper-item v-for="(item, i) in rotation" :key="i" style="width:500px;height:160px;background:url(@/static/banner2.jpg) 0 0 no-repeat;">A
        </swiper-item>-->
        <swiper-item v-for="(item, i) in rotation" :key="i">
          <image :src="item.image"  style="width:100%;height: 100%;" mode="scaleToFill"></image>
        </swiper-item>
      </swiper>
    </view>


<!--    上月收益-->
    <view class="sysy p-t-44 p-b-44">
      <view class="flex-center color-c">上月收益(元) <image class="w-24 h-24 m-l-8" src="@/static/images/ic_gengduo@2x.png"/></view>
      <view style="color: #FFE2C0" class="font-64 m-t-8 flex-center font-weight-900">{{(revenue.in_number_guarant_income + revenue.in_number_amount).toFixed(2)}}</view>
      <view class="flex m-t-44">
        <view class="flex-1 p-l-64">
          <view class="font-28 color-c">合同金额</view>
          <view style="color:#FFE2C0;" class="font-40 m-t-8">{{revenue.furnish_total_cost.toFixed(2)}}</view>
        </view>
        <view class="flex-1 p-l-64">
          <view class="font-28 color-c">已付金额</view>
          <view style="color:#FFE2C0;" class="font-40 m-t-8">{{revenue.furnish_total_paid.toFixed(2)}}</view>
        </view>
      </view>
    </view>

		<!-- 我的收益  -->
		<!-- <Container title="我的收益" text="明细"> -->
<!--			<Container style="font-family: PingFangSC-Medium, sans-serif;color: #1A1A1A;" title="我的收益" >-->
<!--      <view class="flex-between p-t-24" >-->
<!--        <view style="width: 45%;position: relative;" class="df fdc row-center radius-16 back-color-c w-324 h-220 p-l-20 box-shadow" @click="click2()" >-->
<!--          <view style="position: absolute;right:50rpx ;top: 65rpx;"><image style="width: 16rpx;" mode="widthFix" src="../../static/ic_gengduo@3x.png"></image></view>-->
<!--		  <text style="font-family: PingFangSC-Regular, sans-serif;" class="font-40 font-weight-500">上月收益-->
<!--          </text>-->


<!--		  <text v-if="revenue.over" class="font-50 font-weight-700 color-e m-t-16">{{(revenue.in_number_guarant_income + revenue.in_number_amount).toFixed(2)}}</text>-->
<!--		  <text v-else class="font-50 font-weight-700 color-e m-t-16">更新中</text>-->
<!--        </view>-->
<!--        <view style="width: 45%;position: relative;" class="df fdc row-center radius-16 back-color-c w-324 h-220 p-l-20 box-shadow">-->
<!--          <text style="font-family: PingFangSC-Regular, sans-serif;" class="font-40 font-weight-500">累计收益</text>-->
<!--          <text class="font-50 font-weight-700 color-e m-t-16">开发中</text>-->
<!--		  &lt;!&ndash; <text class="font-50 font-weight-700 color-e m-t-16">{{revenue.forecast_earnings.toFixed(2)}}</text> &ndash;&gt;-->

<!--        </view>-->
<!--      </view>-->

<!--&lt;!&ndash;			<view v-if="revenue.contract_status === 0" class="m-t-30 earnings p-t-24 p-b-26 p-l-30 p-r-30 flex-between radius-16">-->
<!--				<view class="flex-col flex-1">-->
<!--					<text class="font-56 font-weight-500">{{numFormat(revenue.price_per_day)}}</text>-->
<!--					<text class="font-24 color-a m-t-20">预计日租金(元/日)</text>-->
<!--				</view>-->
<!--				<view class="divider"></view>-->
<!--				<view class="flex-col col-bottom flex-1">-->
<!--					<text class="font-56 font-weight-500">{{numFormat(revenue.price_per_month)}}</text>-->
<!--					<text class="font-24 color-a m-t-20">预计月租金(元/月)</text>-->
<!--				</view>-->
<!--			</view>-->
<!--			<view v-if="revenue.contract_status === 1" class="m-t-30 earnings p-t-24 p-b-26 p-l-30 p-r-30 flex-between radius-16">-->
<!--				<view class="flex-col flex-1">-->
<!--					<text class="font-56 font-weight-500">{{revenue.in_number_days}}/{{dayNum}}</text>-->
<!--					<text class="font-24 color-a m-t-20">出租率</text>-->
<!--				</view>-->
<!--				<view class="divider"></view>-->
<!--				<view class="flex-col col-bottom flex-1" v-show="false">-->
<!--					<text class="font-56 font-weight-500">{{numFormat(revenue.forecast_earnings)}}</text>-->
<!--					<text class="font-24 color-a m-t-20">本年预估收益(元)</text>-->
<!--				</view>-->
<!--			</view>-->
<!--			<view v-if="revenue.contract_status === 1" class="m-t-30 earnings p-t-24 p-b-26 p-l-30 p-r-30 flex-between radius-16">-->
<!--				<view class="flex-col flex-1">-->
<!--					<text class="font-56 font-weight-500">{{(revenue.in_number_guarant_income + revenue.in_number_amount).toFixed(2)}}</text>-->
<!--					<text class="font-24 color-a m-t-20">上月总收益(元)</text>-->
<!--				</view>-->
<!--				<view class="divider"></view>-->
<!--				<view class="flex-col col-bottom flex-1">-->
<!--					<view class="color-a font-24">保底收益 <text-->
<!--							class="color-d font-weight-500 m-l-10 m-r-10">{{revenue.in_number_guarant_income}}</text>元-->
<!--					</view>-->
<!--					<view class="color-a font-24 m-t-25">分红收益 <text-->
<!--							class="color-d font-weight-500 m-l-10 m-r-10">{{revenue.in_number_amount}}</text>元</view>-->
<!--				</view>-->
<!--			</view>&ndash;&gt;-->
<!--		</Container>-->

		<!-- 我的装修款 -->
<!--		<Container style="font-family: PingFangSC-Medium, sans-serif;" v-if="revenue.furnish_total_cost||revenue.furnish_total_paid" title="我的装修款" text="" url="/pages/home/contract" class="m-t-50">-->
<!--      <view class="df col-center back-color-c radius-16 h-200 m-t-24 box-shadow">-->
<!--        <view class="df fdc row-center flex-1 p-l-20">-->
<!--          <text class="font-50 color-d font-weight-500">{{revenue.furnish_total_cost.toFixed(2)}}</text>-->
<!--          <text style="font-family: PingFangSC-Regular, sans-serif;" class="font-35 color-a p-t-20">合同金额</text>-->
<!--        </view>-->
<!--        <view class="w-2 h-40 back-color-g"></view>-->
<!--        <view class="df fdc row-center flex-1 p-l-20">-->
<!--          <text class="font-50 color-d font-weight-500">{{revenue.furnish_total_paid.toFixed(2)}}</text>-->
<!--          <text style="font-family: PingFangSC-Regular, sans-serif;" class="font-35 color-a p-t-20">已付金额</text>-->
<!--        </view>-->
<!--      </view>-->
<!--&lt;!&ndash;			<view class="flex back-color-b p-l-20 p-t-26 p-r-20 p-b-26 radius-16 m-t-30">-->
<!--				<view class="flex-col flex-1">-->
<!--					<text class="opy-6 font-24 color-c">已签合同数量（份）</text>-->
<!--					<text class="color-c font-68 font-weight-500">{{data.contract_yes_num}}</text>-->
<!--				</view>-->
<!--				<view class="flex-col flex-1">-->
<!--					<text class="opy-6 font-24 color-c">待签合同数量（份）</text>-->
<!--					<text class="color-c font-68 font-weight-500">{{data.contract_no_num}}</text>-->
<!--				</view>-->
<!--			</view>&ndash;&gt;-->
<!--		</Container>-->

		<!-- 资产信息 -->
		<Container title="资产信息" text="查看更多" url="/pages/home/assets" class="m-t-50">
			<block v-for="(item, i) in data.landlord_assets" :key="i">
			<view class="bg box-shadow" :class="item.css" @click="click(item)">
        <view>
          <image src="@/static/images/index/ic_zichan@2x.png"  style="width:50px;" mode="widthFix"></image>
        </view>
        <view class="flex-col m-l-20" style="overflow: hidden;">
          <text style="font-family: PingFangSC-Regular, sans-serif;" class="opy-6 font-24 color-a">
            {{item.province_name}}{{item.city_name}}{{item.district_name}}
            <text class="zizhan-status">{{item.status_str}}</text>
          </text>
          <text style="font-family: PingFangSC-Medium, sans-serif;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width: 100%;" class="color-d font-36 font-weight-500 m-t-20">{{item.address}}</text>
        </view>
			</view>
			</block>
		</Container>

		<Watermark color='#FFF1F1' :watermark="mark" :maxWidth="200" />
	</view>
</template>

<script>
	import Container from '@/components/home/Container'
	import {
		checkUpdate
	} from "@/components/yzhua006-update/js/app-update-check.js";
	export default {
		components: {
			Container,
		},
		data() {
			return {
				data: {},
				revenue: {},
        rotation: [

        ],
        operation_asset_id:0
			}
		},
		onLoad(ops) {
      console.log(ops)
      if(ops.mobile){
        uni.setStorageSync('login_mobile', ops.mobile)
      }
			// #ifdef APP-PLUS
			this.getAppInfo()
			// #endif
		},
		onShow() {
			if (this.isObjNone(this.user)) {
				this.getHousingTotalRevenue()
				this.landlord()
			} else {
				uni.showToast({
					icon: 'none',
					title: '请登录！',
				})
				setTimeout(() => {
					this.toLogin()
				}, 2000)
			}
			this.messageCenter();
		},
		computed: {
			dayNum() {
				let time = new Date()
				let month = time.getMonth() === 0 ? 1 : time.getMonth(),
					year = time.getMonth() === 0 ? time.getFullYear() - 1 : time.getFullYear()
				return new Date(year, month, 0).getDate()
			}
		},
		methods: {
			async getHousingTotalRevenue() {
				const res = await this.$api.common.landlord('getHousingTotalRevenue', {
					time: '',
					assets_id: ''
				})
				if (res.code === 200) {
					this.revenue = res.data
				}
			},
			// 首页
			async landlord() {
				const res = await this.$api.common.landlord('getIndex')
				if (res.code === 200) {
					var list = res.data.landlord_assets;
					this.rotation=res.data.banner;
					for(let i = 0; i<list.length;i++){
						if(list[i]['contract_status'] == 0){
							list[i]['css'] = "bg";
							list[i]['status_str'] = "未签约";
						}else{
							if(list[i]['status'] == 1){
								list[i]['css'] = "bg1";
								list[i]['status_str'] = "运营中";
                this.operation_asset_id = list[i]['assets_id']

							}else{
								let arr={'装修准备中':0,'硬装开工':4,'浇筑完工':8,'水电施工中':10,'水电完工':12,'泥瓦施工中':14,'泥瓦完工':16,'油漆施工中':18,'油漆完工':20,'硬装完工':40,'软装配置中':50,'软装完工':60,'验收完成':80};

								for(let index in arr){
									if(arr[index]==list[i]['renovation_status']){
										list[i]['status_str'] = index;
										if(arr[index]<60){
											list[i]['css'] = "bg2";

										}else{
											list[i]['css'] = "bg3";
										}
										break
									}

								}


							}
						}
					}
					res.data.landlord_assets = list;
					this.data = res.data
				}
			},
			click(item) {
				this.$store.commit('SET_SELECT_ASSETS', item)
				if(item.status == 1&&item.contract_status == 1){
					this.jump(`/pages/user/assets-details2?id=${item.assets_id}`,true)
				}else{
					this.jump(`/pages/user/assets-details?id=${item.assets_id}`,true)
				}
			},
			click2() {
				this.$store.commit('SET_SELECT_ASSETS', item)
				if(this.operation_asset_id&&this.revenue.over){
					this.jump(`/pages/user/assets-details2?id=${this.operation_asset_id}`,true)
				}
			},
			async getAppInfo(type) {
				const system_info = uni.getSystemInfoSync();
				let params = {
						os: system_info.platform //本机设备操作系统  （android || ios）
					},
					api = 'iosVersionUpdate'
				if (params.os === 'android') api = "androidVersionUpdate"
				if (params.os != 'ios' && params.os != 'android') false; //如果不是安卓或ios 返回false

				//这里自行请求API获取版本信息 建议传入操作系统标识，返回本机对应的操作系统最新版本信息，也就是安卓的返回就是安卓的版本信息  ios返回就是ios的版本信息

				//请求获取最新版本
				plus.runtime.getProperty(plus.runtime.appid, async (inf) => {
					let params = {
						version: inf.version
					}
					const res = await this.$api.common.system(api, params)
					if (res.code === 200 && this.isListNone(res.data)) {
						let update_info = {
							version: res.data.version, //线上版本
							now_url: res.data.path, //更新链接
							silent: 0, //是否是静默更新
							force: 1, //是否是强制更新
							net_check: 1, //非WIfi是否提示
							note: res.data.remark, //更新内容
						}
						checkUpdate(update_info, type, inf.version).then(res => {
							console.log(res);
							if (res.msg) {
								// #ifdef APP-PLUS
								plus.nativeUI.toast(res.msg);
								// #endif
								// this.jump(`/pages/index/app-update?update_info=${res}`)
							}
						}); ///检查更新
						//checkUpdate 这个方法会做什么？：线上版本号 与 本地版本号做对比 ，如果需要更新  根据静默，强制、wifi等信息执行静默更新或跳转到升级页面
						//跳转升级页面的前提是，需要新建并在pages.json中配置升级页面，配置方法请查看插件详情
					}
				})
			},
			async messageCenter() {
				const msgCenter = await this.$api.common.system('messageCenter')
				try {
					if (msgCenter.code === 200 && (msgCenter.data.last_order_msg.unread_num || msgCenter.data.last_system_msg.unread_num)) {
						uni.showTabBarRedDot({
							index:1
						})
					}
				}
				catch(err) {}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.earnings {
		background-color: #fff;

		.divider {
			width: 1rpx;
			height: 40rpx;
			background: #EEEEEE;
		}
	}

	.bg {
    /*position: relative;
    top: 10px;
    right: 10px;
    color:#808080;
    border-radius: 10px;
    font-size: 14px;
    padding: 5px 15px;*/


    display: flex;
    flex-direction: row;
    //justify-content: center;
    height: 136rpx;
    padding: 40rpx 184rpx 0 20rpx;
    border-radius: 16rpx;
    margin-bottom: 15rpx;
    margin-top: 15rpx;
    position: relative;
    background: #fff;
    font-weight: bold;
    box-shadow: 0px 2px 16px 0px rgba(0,0,0,0.1);
		//background: url(@/static/images/user/bg_zichan_moni_hui_2@2x.png) 0 0 no-repeat;
		//background-size: 100% 100%;
	}

  .zizhan-status{
    position: absolute;
    top: 20px;
    right: 10px;
    //color:#fff;
    font-size: 14px;
    padding: 5px 15px;
    border-radius: 12px;
  }

  .sysy{
    width: 690rpx;
    background: linear-gradient( 27deg, #FB2D19 0%, #F94848 70%, #FE7D7D 100%);
    border-radius: 24rpx;
  }

</style>
